<?php

/**
*
* @Author: Darius Kasperavicius
* @Email: damdam@bk.ru
*	www.tinkama.lt
*
*/

class Breadcrumb_model extends Model
{

	// Constructor
	public function __construct()
	{
		parent::Model();
		
		$this->_table = $this->config->item('database_tables');
		//$this->find_data();
		
	}

	/**
	 * Main functions
	 *
	 */
	
	function set_type($type) {
		$this->type = $type;
	}
	
	function set_data($data) {
		$this->data = $data;
	}

	function set_from($from) {
		$this->from = $from;
	}
	
	function get_data($get_breadcrumb, $type = '', $is_common = false)
	{
		if ($is_common)
		{
			$function = 'get_' . $get_breadcrumb;
		}
		else 
		{
			$function = 'get_' . $get_breadcrumb . '_from_' . $type;
		}
		
		return $this->$function();
	}
	
	
	/**
	 * 
	 * Curstom functions
	 *
	 */
	
	function get_artists() {
		
		
		$bc = array(
               'title' => 'Artists',
               'url' => 'lyrics/artists',
               'isRoot' => false,
        	);
		
		return $bc;
	}
	
	
	function get_artist_from_lyrics () {
		if (!$this->artist) 
		{
			$id = $this->uri->segment(2);
			$this->load->module_model('lyrics', 'lyrics_model', 'lyrics');
			$artist = $this->lyrics->get_artist_by_lyrics($id, $url_title);
			
			$this->artist = array(
	               'title' => $artist->g_term,
	               'url' => 'lyrics/songs/' . $artist->g_id,
	               'isRoot' => false,
	        	);
		}	
		return $this->artist;
	}
	
	function get_letter_from_artist() {
		if (!$this->letter)
		{
			if (!$this->data['title']) return false;
			
			$letter = substr($this->data['title'], 0,1);
			
			$this->letter = array(
	               'title' => $letter,
	               'url' => 'lyrics/artists/term/' . $letter,
	               'isRoot' => false,
	        	);
	        	
			return $this->letter;
		}
		return $this->letter;
	}
	
	function get_letter_from_lyrics() {
		if (!$this->letter)
		{
			
			if ($this->artist) 
			{
				$artist_title = $this->artist['title'];
				$letter = substr($this->artist['title'], 0,1);
			}
			elseif($this->data['artist_name'])
			{
				$artist_title = $this->data['artist_name']->g_term;
			}
			else return false;
			
			$letter = substr($artist_title, 0,1);
			
			$this->letter = array(
	               'title' => $letter,
	               'url' => 'lyrics/artists/term/' . $letter,
	               'isRoot' => false,
	        	);
			return $this->letter;
		}
		return $this->letter;
	}
}

/* End of file breadcrumb_model.php */
